package com.lemon.smartsafetynew.ui.fragment.highDanger;

import android.os.Bundle;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafetynew.entity.electrical.ElectricalCompanyVo;
import com.lemon.smartsafetynew.entity.highDanger.HighDangerItemVo;
import com.lemon.smartsafetynew.net.services.MonitorServices;
import com.lemon.smartsafetynew.ui.adapter.highDanger.HighDangerItemAdapter;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.lemon.smartsafetynew.util.user.AccountUtil;
import com.lemon.smartsafetynew.util.user.UserTypeUtil;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 实时监测 -- 高危工艺监测列表
 * Created by Andrew on 2018/3/17.
 */

public class HighDangerListFragment extends BasePullToRefreshFragment<HighDangerItemVo, List<HighDangerItemVo>> {

    private static ElectricalCompanyVo companyVo = null;

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();

        Bundle bundle = getArguments();

        if (bundle != null) {
            if (bundle.containsKey(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO)) {
                companyVo = (ElectricalCompanyVo) bundle.getSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO);
            }
        }
    }

    public static HighDangerListFragment newInstance(ElectricalCompanyVo data) {

        Bundle args = new Bundle();
        if (data != null) {
            args.putSerializable(KeyConstants.KEY_ELECTRICAL_COMPANY_INFO, data);
        }

        HighDangerListFragment fragment = new HighDangerListFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onPullRefresh() {

        LemonRequestParams params = new LemonRequestParams("");
        if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
            params.put("company_id", AccountUtil.getCompanyId());
        } else {
            if(companyVo != null) {
                params.put("company_id", companyVo.getCompanyId());
            }
        }

        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        MonitorServices.init().getHighDangerList(RefreshType.REFRESH, params);
    }

    @Override
    public void onLoadMore() {

        LemonRequestParams params = new LemonRequestParams("");
        if (!UserTypeUtil.isGovType(AccountUtil.getUserType())) { //非政府人员使用模块
            params.put("company_id", AccountUtil.getCompanyId());
        } else {
            if(companyVo != null) {
                params.put("company_id", companyVo.getCompanyId());
            }
        }

        params.put("pageNum", currentPage);
        params.put("pageSize", pageSize);
        MonitorServices.init().getHighDangerList(RefreshType.LOAD_MORE, params);
    }

    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<HighDangerItemVo> getLemonAdapter() {
        return new HighDangerItemAdapter(mDataList);
    }

    @Override
    public String getHttpTag() {
        return KeyConstants.URL_GET_MONITOR_HIGH_DANGER_LIST;
    }
}
